using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Commons;
using WP.DB;

namespace WP.Modules
{
    public partial class frmEntryPassword : BaseQryRpt
    {
        private string m_strPassword = "";

        private bool mblnIsSystemPassword = false;


        public frmEntryPassword(string Password, bool blnIsSystemPassword)
        {
            InitializeComponent();
            mblnIsSystemPassword = blnIsSystemPassword;
            m_strPassword = Password;
        }

        public frmEntryPassword(string Password)
        {
            InitializeComponent();
            m_strPassword = Password;
        }

        #region Private Events

        private void btnOk_Click(object sender, EventArgs e)
        {
            bool bRight = false;

            if (this.txtPassword.Text.Trim() != "")
            {
                bRight = JudgePasswordRight();
                if (bRight)
                {
                    this.DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    this.txtPassword.Text = "";
                    this.txtPassword.Focus();
                }
            }
            else
            {
                this.txtPassword.Focus();
            }
        }
        #endregion

        #region Private Functions
        private bool JudgePasswordRight()
        {
            bool bRight = false;

            try
            {
                if (mblnIsSystemPassword)
                {
                    m_strPassword = BaseFunctions.SystemSettingPassword();  
                }
                if (this.txtPassword.Text == m_strPassword)
                    bRight = true;
            }
            catch
            {
                bRight = false;
            }

            return bRight;
        }

        private string GetPassword()
        {
            string strPassword = "";
  ////          string strSQL = "";
  ////          WP.DB.DBAccess dBAccess=null;

  ////          if (m_strFormula.Trim() != "")
  ////          {
  ////              m_strFormula = m_strFormula.Replace("[Y]", System.DateTime.Today.Year.ToString());
  ////              m_strFormula = m_strFormula.Replace("[M]", System.DateTime.Today.Month.ToString());
  ////              m_strFormula = m_strFormula.Replace("[D]", System.DateTime.Today.Day.ToString());
  //////            m_strFormula = m_strFormula.Replace("[H]", System.DateTime.Today.Year.ToString());

  ////              strSQL = "SELECT " + m_strFormula;
  ////              dBAccess = new DBAccess();
  ////              strPassword = dBAccess.GetIntValue(strSQL).ToString();

  ////          }

            return strPassword;
        }
        #endregion
    }
}